package cn.itcast.health.provider.service.logimpl;


import cn.itcast.health.commons.entity.QueryPageBean;
import cn.itcast.health.commons.entity.Result;
import cn.itcast.health.commons.resources.MessageConstant;
import cn.itcast.health.interfaces.logservice.LogBusinessFace;
import cn.itcast.health.logsmapper.LogBusinessFaceMapper;
import cn.itcast.health.pojo.CheckItem;
import cn.itcast.health.vo.LogBusinessVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogBusinessFaceImpl implements LogBusinessFace {

    @Autowired
    private LogBusinessFaceMapper logBusinessFaceMapper;

    @Override
    @Transactional
    public void SaveLogBusiness(LogBusinessVo logBusiness) {
        logBusinessFaceMapper.SaveLogBusiness(logBusiness);
    }

    @Override
    public Result findByPageJournalData(QueryPageBean queryPageBean) {
        Result result = null;
        try {
            //设置分页条件
            PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
            //查询数据
            List<LogBusinessVo> logBusinessVos = logBusinessFaceMapper.findByPageJournalData(queryPageBean.getQueryString(),queryPageBean.getTiaojian());
            PageInfo pageInfo = new PageInfo(logBusinessVos);
            Map<String,Object> map = new HashMap();
            map.put("list",pageInfo.getList());
            map.put("total",pageInfo.getTotal());
            result = new Result(true, MessageConstant.QUERY_LOG_SUCCESS,map);
        }catch (Exception e){
            result = new Result(false,MessageConstant.QUERY_LOG_FAIL);
        }
        return result;
    }
}
